package com.smxy.hunzi.user.valid.constraintvalidator;

import com.smxy.hunzi.user.valid.validannotation.PasswordValid;

import javax.validation.ConstraintValidator;
import javax.validation.ConstraintValidatorContext;

/**
 * @author 李涛
 * @date 2020-08-14 16:59
 */
public class PasswordConstraintValidator implements ConstraintValidator<PasswordValid,String> {
    @Override
    public void initialize(PasswordValid constraintAnnotation) {

    }

    @Override
    public boolean isValid(String value, ConstraintValidatorContext context) {
        if(value == null)
            return false;
        if(value.contains(" ")){
            return false;
        }
        return value.length() >= 6 && value.length() <= 16;
    }
}
